<?php
class message
{
    private $db;
    private $table;
    public $type_list;

    public $pages;//返回分页URL

    public function __construct() {
        global $db;
        $this->db = &$db;
        $this->table = DB_PRE.'message';
        $this->type_list = array(
            1   =>  '学习答疑',
            2   =>  '报名咨询',
            3   =>  '管理建议'
        );
    }

    /**
	 * 添加角色信息
	 *
	 * @param ARRAY() $data
	 * @return 	INT or FALSE
	 */
    public function add( $data )
    {
        $params = $data;
        $res = $this->db->insert( $this->table, $params );
		return $res;
    }

    


    /**
	 * 删除角色信息
	 *
	 * @param INT $rid
	 * @return BOOL
	 */
    public function del( $id )
    {
        $this->db->prepare('delete from ' . $this->table . ' where id=?');
        $this->db->set_int($id);
        $res = $this->db->execute();
        return $res;
    }

    /**
	 * 查询所有角色列表信息
	 *
	 * @param ARRAY() $params, STRING $order, INT $page, INT $pagesize
	 * @return 	ARRAY() $list
	 */
    public function get_list( $page=1, $pagesize=10 )
    {
        
        $this->db->prepare( "SELECT count(*) as nums FROM $this->table" );
		$res = $this->db->execute( true );
		$nums = isset( $res['nums'] ) ? intval( $res['nums'] ) : 0;
        $this->pages = pages( $nums, $page, $pagesize );
		$this->db->prepare( "SELECT * FROM $this->table order by id desc limit ?, ?" );
		$this->db->set_int( ( $page-1 ) * $pagesize );
		$this->db->set_int( $pagesize );
	    $list = $this->db->execute();
        return $list;
    }

   
}
?>